package service

import (
	"encoding/json"
	"net/http"

	"github.com/gin-gonic/gin"
	"github.com/sirupsen/logrus"
)

const baseUrl_bj = "http://10.93.1.46/wjzwfw/rest/"

// 近三年全区办件量接口 左3
func GetNearlyHalf(c *gin.Context) {
	url := baseUrl_bj + "changsanjiaohall/annualComparison"
	data := []byte(`params%3D%7B%22areacode%22%3A%20%22all%22%2C%22centerguid%22%3A%20%22all
 %22%7D `)
	nearlyResponse, err := Post[ResponsePack[AnnualComparisonResponseBody[[]AnnualComparisonParams]]](url, data, c)
	if err != nil {
		c.JSON(http.StatusOK, ErrorResponse(0, err))
		return
	}
	c.JSON(http.StatusOK, SuccessResponse(nearlyResponse.Custom.RewsList))
}

func GetHotTop5(c *gin.Context) {

}

// 右上1图表
func GetXzxkPercent(c *gin.Context) {
	url := baseUrl_bj + "bigscreendata/getXzxkPercent"
	data := []byte(`{}`)
	Response, err := Post[ResponsePack[TaskList]](url, data, c)
	if err != nil {
		c.JSON(http.StatusOK, ErrorResponse(0, err))
		return
	}
	c.JSON(http.StatusOK, SuccessResponse(Response.Custom.TaskList))
}

// 获取乡镇的各个事项当天的取号数量
func GetCenterTaskTypeQhCountByAreaCode(c *gin.Context) {
	url := baseUrl_bj + "wjbigscreen/getCenterTasktypeQhCountByAreacode"
	var params CenterTaskTypeQhCountByAreaParams
	if err := c.ShouldBindJSON(&params); err == nil {
		jsonData, errJson := json.Marshal((params))
		if errJson != nil {
			logrus.Error(errJson)
		}
		data := []byte(jsonData)
		Response, err1 := Post[CenterTaskTypeQhCountByAreaResponse](url, data, c)
		if err1 != nil {
			c.JSON(http.StatusOK, ErrorResponse(0, err1))
			return
		}
		c.JSON(http.StatusOK, SuccessResponse(Response.List))
	} else {
		c.JSON(http.StatusOK, ErrorResponse(0, err))
	}
}

// 获取大类排队等候
func GetzqinfoList(c *gin.Context) {
	url := "https://10.93.1.46/wjzwdt/rest/indexcontroller/getzqinfolist"
	var params ZqInfoParams[ZqInfoListParamsItem]
	if err := c.ShouldBindJSON(&params); err == nil {
		jsonData, errJson := json.Marshal((params))
		if errJson != nil {
			logrus.Error(errJson)
		}
		data := []byte(jsonData)
		Response, ResErr := Post[ResponsePack[ZqInfoListResponse]](url, data, c)
		if ResErr != nil {
			c.JSON(http.StatusOK, ErrorResponse(0, err))
			return
		}
		c.JSON(http.StatusOK, SuccessResponse(Response.Custom.Slide))
	} else {
		c.JSON(http.StatusOK, ErrorResponse(0, err))
	}
}

// 获取小类排队等候
func GetzqList(c *gin.Context) {
	url := "https://10.93.1.46/wjzwdt/rest/indexcontroller/gettaskinfolist"
	var params ZqInfoParams[ZqListParamsItem]
	if err := c.ShouldBindJSON(&params); err == nil {
		jsonData, errJson := json.Marshal((params))
		if errJson != nil {
			logrus.Error(errJson)
		}
		data := []byte(jsonData)
		Response, err1 := Post[ResponsePack[ZqListResponse]](url, data, c)
		if err1 != nil {
			c.JSON(http.StatusOK, ErrorResponse(0, err1))
			return
		}
		c.JSON(http.StatusOK, SuccessResponse(Response.Custom))
	} else {
		c.JSON(http.StatusOK, ErrorResponse(0, err))
	}
}
